import cv2
from skimage.metrics import structural_similarity as ssim
# 读取两张图片
image1 = cv2.imread("C1.jpg")
image2 = cv2.imread("C.jpg")

# 将图片转换为灰度图像
gray_image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
gray_image2 = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)

# 计算图片的结构相似性指数（SSIM）
# ssim_score, diff_image = ssim(gray_image1, gray_image2, full=True)
# # 打印相似度
# print("SSIM Score:", ssim_score)
# 计算直方图
hist1 = cv2.calcHist([gray_image1], [0], None, [256], [0,256])
hist2 = cv2.calcHist([gray_image2], [0], None, [256], [0,256])
similarity = cv2.compareHist(hist1, hist2, cv2.HISTCMP_BHATTACHARYYA)

print("Histogram Similarity:", 1-similarity)
# 显示差异图像
# cv2.imshow("Difference Image", similarity)
# cv2.waitKey(0)
# cv2.destroyAllWindows()